package com.ruoyi.quartz.service.impl;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.quartz.mapper.LotteryRecordMapper;
import com.ruoyi.quartz.service.ISynchronousLotteryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;


@Service
public class SynchronousLotteryDataServiceImpl implements ISynchronousLotteryService {

    @Autowired
    private LotteryRecordMapper recordMapper;

    @Autowired
    private RedisCache redisCache;


    /**
     * 同步中奖人数
     */
    @Override
    public void syncLotteryWinNum() {
        Integer integer = recordMapper.countWinNumLotteryByIndex(4);
        if (ObjectUtils.isEmpty(integer)) {
            integer = 0;
        }
        System.out.println("中奖人数：" + integer);
        String key = "app.config.cache.key.lottery.win.num";
        redisCache.setCacheObject(key, integer);
    }

    /**
     * 同步用户数据
     *
     * @param id
     */
    @Override
    public void syncLotteryLotteryData(Long id) {
        recordMapper.syncLotteryLotteryData(id);
    }
}
